FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/modules/dasUnitTest/test_handles.cpp at master · WhyNot135/daScript · GitHub
WhyNot135
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
modules
/
dasUnitTest
/
test_handles.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
726 lines (660 loc) · 31.3 KB
Breadcrumbs
daScript
/
modules
/
dasUnitTest
/
test_handles.cpp
Copy path
File metadata and controls
726 lines (660 loc) · 31.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
#
include
"
daScript/misc/platform.h
"
#
include
"
unitTest.h
"
#
include
"
module_unitTest.h
"
#
include
"
daScript/simulate/simulate_visit_op.h
"
#
include
"
daScript/ast/ast_policy_types.h
"
int32_t
TestObjectSmart::total =
0
;
//
sample of your-engine-float3-type to be aliased as float3 in daslang.
template
<>
struct
das
::cast <Point3> : cast_fVec<Point3> {};
namespace
das
{
template
<>
struct
typeFactory
<Point3> {
static
TypeDeclPtr
make
(
const
ModuleLibrary &) {
auto
t =
new
TypeDecl
(Type::tFloat3);
t->
alias
=
"
Point3
"
;
t->
aotAlias
=
true
;
return
t;
}
};
template
<>
struct
typeName
<Point3> {
constexpr
static
const
char
*
name
() {
return
"
Point3
"
; } };
}
DAS_BASE_BIND_ENUM_98
(SomeEnum_16, SomeEnum_16, SomeEnum_16_zero, SomeEnum_16_one, SomeEnum_16_two)
DAS_BASE_BIND_ENUM_98
(OpCode, OpCode, op_nop, op_mov_a_arg, op_mov_arg_b, op_dec_a, op_cmple_a_low_zx, op_cjmp, op_mov_c_a, op_mov_a_low_zx, op_mov_b_low_zx, op_xchange_a_b, op_add_b_a, op_loop, op_return_b)
//
sample of your engine annotated struct
MAKE_TYPE_FACTORY
(TestObjectSmart,TestObjectSmart)
MAKE_TYPE_FACTORY
(TestObjectFoo,TestObjectFoo)
MAKE_TYPE_FACTORY
(TestObjectBar, TestObjectBar)
MAKE_TYPE_FACTORY
(TestObjectNotLocal, TestObjectNotLocal)
MAKE_TYPE_FACTORY
(TestObjectNotNullPtr, TestObjectNotNullPtr)
MAKE_TYPE_FACTORY
(FancyClass, FancyClass)
MAKE_TYPE_FACTORY
(SomeDummyType, SomeDummyType)
MAKE_TYPE_FACTORY
(Point3Array, Point3Array)
MAKE_TYPE_FACTORY
(ByteCode, ByteCode)
namespace
das
{
template
<>
struct
typeFactory
<SampleVariant> {
static
TypeDeclPtr
make
(
const
ModuleLibrary & library ) {
auto
vtype =
new
TypeDecl
(Type::tVariant);
vtype->
alias
=
"
SampleVariant
"
;
vtype->
aotAlias
=
true
;
vtype->
addVariant
(
"
i_value
"
, typeFactory<
decltype
(SampleVariant::i_value)>::
make
(library));
vtype->
addVariant
(
"
f_value
"
, typeFactory<
decltype
(SampleVariant::f_value)>::
make
(library));
vtype->
addVariant
(
"
s_value
"
, typeFactory<
decltype
(SampleVariant::s_value)>::
make
(library));
//
optional validation
DAS_ASSERT
(
sizeof
(SampleVariant) == vtype->
getSizeOf
());
DAS_ASSERT
(
alignof
(SampleVariant) == vtype->
getAlignOf
());
DAS_ASSERT
(
offsetof
(SampleVariant, i_value) == vtype->
getVariantFieldOffset
(
0
));
DAS_ASSERT
(
offsetof
(SampleVariant, f_value) == vtype->
getVariantFieldOffset
(
1
));
DAS_ASSERT
(
offsetof
(SampleVariant, s_value) == vtype->
getVariantFieldOffset
(
2
));
return
vtype;
}
};
};
struct
TestObjectNotLocalAnnotation
: ManagedStructureAnnotation <TestObjectNotLocal> {
TestObjectNotLocalAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
TestObjectNotLocal
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(fooData)>(
"
fooData
"
);
}
virtual
bool
isLocal
()
const
{
return
false
; }
//
this is here so that the class is not local
virtual
bool
canBePlacedInContainer
()
const
{
return
false
; }
//
this can't be in the container either
};
struct
TestObjectNotNullPtrAnnotation
: ManagedStructureAnnotation <TestObjectNotNullPtr> {
TestObjectNotNullPtrAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
TestObjectNotNullPtr
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(fooData)>(
"
fooData
"
);
}
virtual
bool
avoidNullPtr
()
const
override
{
return
true
; }
//
obvious null-ptr-ing this object is an error
};
struct
TestObjectSmartAnnotation
: ManagedStructureAnnotation <TestObjectSmart> {
TestObjectSmartAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
TestObjectSmart
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(fooData)>(
"
fooData
"
);
}
void
init
() {
//
this needs to be separate
//
reason: recursive type
addField<
DAS_BIND_MANAGED_FIELD
(first)>(
"
first
"
);
}
};
struct
TestObjectFooAnnotation
: ManagedStructureAnnotation <TestObjectFoo> {
TestObjectFooAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
TestObjectFoo
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(hit)>(
"
hit
"
);
addField<
DAS_BIND_MANAGED_FIELD
(lookAt)>(
"
lookAt
"
);
addField<
DAS_BIND_MANAGED_FIELD
(fooData)>(
"
fooData
"
);
addField<
DAS_BIND_MANAGED_FIELD
(
e16
)>(
"
e16
"
);
addProperty<
DAS_BIND_MANAGED_PROP
(propAdd13)>(
"
propAdd13
"
);
addProperty<
DAS_BIND_MANAGED_PROP
(hitPos)>(
"
hitPos
"
);
addProperty<
DAS_BIND_MANAGED_PROP
(hitPosRef)>(
"
hitPosRef
"
);
addPropertyExtConst<
bool
(TestObjectFoo::*)(), &TestObjectFoo::isReadOnly,
bool
(TestObjectFoo::*)()
const
, &TestObjectFoo::isReadOnly
>(
"
isReadOnly
"
,
"
isReadOnly
"
);
addField<
DAS_BIND_MANAGED_FIELD
(fooArray)>(
"
fooArray
"
);
addProperty<
DAS_BIND_MANAGED_PROP
(getWordFoo)>(
"
wordFoo
"
,
"
getWordFoo
"
);
}
void
init
() {
addField<
DAS_BIND_MANAGED_FIELD
(foo_loop)>(
"
foo_loop
"
);
addPropertyExtConst<
TestObjectFoo * (TestObjectFoo::*)(), &TestObjectFoo::getLoop,
const
TestObjectFoo * (TestObjectFoo::*)()
const
, &TestObjectFoo::getLoop
>(
"
getLoop
"
,
"
getLoop
"
);
}
};
struct
TestObjectBarAnnotation
: ManagedStructureAnnotation <TestObjectBar> {
TestObjectBarAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
TestObjectBar
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(fooPtr)>(
"
fooPtr
"
);
addField<
DAS_BIND_MANAGED_FIELD
(barData)>(
"
barData
"
);
addFieldEx
(
"
simple_string
"
,
"
simple_string
"
,
offsetof
(TestObjectBar, simple_string), das::makeType<
char
*>(ml));
addProperty<
DAS_BIND_MANAGED_PROP
(getFoo)>(
"
getFoo
"
);
addProperty<
DAS_BIND_MANAGED_PROP
(getFooPtr)>(
"
getFooPtr
"
);
}
};
void
testAdd
(
int
& a,
int
b ) {
a += b;
}
struct
CheckRange
: StructureAnnotation {
CheckRange
() : StructureAnnotation(
"
checkRange
"
) {}
virtual
bool
touch
(
const
StructurePtr & st, ModuleGroup &,
const
AnnotationArgumentList & args, string & )
override
{
//
this is here for the 'example' purposes
//
lets add a sample 'dummy' field
if
(args.
getBoolOption
(
"
dummy
"
,
false
) && !st->
findField
(
"
dummy
"
)) {
st->
fields
.
emplace_back
(
"
dummy
"
,
new
TypeDecl
(Type::tInt),
nullptr
/*
init
*/
,
AnnotationArgumentList
(),
false
/*
move_to_init
*/
,
LineInfo
());
st->
fieldLookup
.
clear
();
}
return
true
;
}
virtual
bool
look
(
const
StructurePtr & st, ModuleGroup &,
const
AnnotationArgumentList & args, string & err )
override
{
bool
ok =
true
;
if
(!args.
getBoolOption
(
"
disable
"
,
false
)) {
for
(
auto
& fd : st->
fields
) {
if
(fd.
type
->
isSimpleType
(Type::tInt) && fd.
annotation
.
size
()) {
int32_t
val =
0
;
int32_t
minVal =
INT32_MIN
;
int32_t
maxVal =
INT32_MAX
;
if
(fd.
init
&& fd.
init
->
rtti_isConstant
()) {
val =
static_cast
<ExprConstInt*>(fd.
init
)->
getValue
();
}
if
(
auto
minA = fd.
annotation
.
find
(
"
min
"
, Type::tInt)) {
minVal = minA->
iValue
;
}
if
(
auto
maxA = fd.
annotation
.
find
(
"
max
"
, Type::tInt)) {
maxVal = maxA->
iValue
;
}
if
(val<minVal || val>maxVal) {
err += fd.
name
+
"
out of annotated range [
"
+
to_string
(minVal) +
"
..
"
+
to_string
(maxVal) +
"
]
\n
"
;
ok =
false
;
}
}
}
}
return
ok;
}
};
void
test_das_string
(
const
Block & block, Context * context, LineInfoArg * at) {
string str =
"
test_das_string
"
;
string str2;
vec4f args[
2
];
args[
0
] = cast<
void
*>::
from
(&str);
args[
1
] = cast<
void
*>::
from
(&str2);
context->
invoke
(block, args,
nullptr
, at);
if
(str !=
"
out_of_it
"
) context->
throw_error_at
(at,
"
test string mismatch
"
);
if
(str2 !=
"
test_das_string
"
) context->
throw_error_at
(at,
"
test string clone mismatch
"
);
}
void
testPipedDefaults
(
int32_t
a,
float
b,
const
TBlock<
void
,
int32_t
,
float
> & blk, Context * context, LineInfoArg * at) {
das_invoke<
void
>::
invoke
(context, at, blk, a, b);
}
vec4f
new_and_init
( Context & context, SimNode_CallBase * call, vec4f * ) {
TypeInfo * typeInfo = call->
types
[
0
];
if
( typeInfo->
dim
|| typeInfo->
type
!=Type::tStructure ) {
context.
throw_error_at
(call->
debugInfo
,
"
invalid type
"
);
return
v_zero
();
}
auto
size =
getTypeSize
(typeInfo);
auto
data = context.
allocate
(size, &call->
debugInfo
);
if
( typeInfo->
structType
&& typeInfo->
structType
->
init_mnh
) {
auto
fn = context.
fnByMangledName
(typeInfo->
structType
->
init_mnh
);
context.
callWithCopyOnReturn
(fn,
nullptr
, data,
0
);
}
else
{
memset
(data,
0
, size);
}
return
cast<
char
*>::
from
(data);
}
int
g_st =
0
;
int
*
getPtr
() {
return
&g_st;}
uint2
get_screen_dimensions
() {
return
uint2{
1280
,
720
};}
uint64_t
CheckEid
( TestObjectFoo & foo,
char
*
const
name, Context * context, LineInfoArg * at ) {
if
(!name) context->
throw_error_at
(at,
"
invalid id
"
);
return
hash_function
(*context, name) + foo.
fooData
;
}
uint64_t
CheckEidHint
( TestObjectFoo & foo,
char
*
const
name,
uint64_t
hashHint, Context * context, LineInfoArg * at ) {
if
(!name) context->
throw_error_at
(at,
"
invalid id
"
);
uint64_t
hv =
hash_function
(*context, name) + foo.
fooData
;
if
( hv != hashHint ) context->
throw_error_at
(at,
"
invalid hash value
"
);
return
hashHint;
}
struct
CheckEidFunctionAnnotation
: TransformFunctionAnnotation {
CheckEidFunctionAnnotation
() : TransformFunctionAnnotation(
"
check_eid
"
) { }
virtual
ExpressionPtr
transformCall
( ExprCallFunc * call, string & err )
override
{
auto
arg = call->
arguments
[
1
];
if
( arg->
type
&& arg->
type
->
isString
() && arg->
type
->
isConst
() && arg->
rtti_isConstant
() ) {
auto
starg =
static_cast
<ExprConstString*>(arg);
if
(!starg->
getValue
().
empty
()) {
auto
hv =
hash_blockz64
((
uint8_t
*)starg->
text
.
c_str
());
auto
hconst =
new
ExprConstUInt64
(arg->
at
, hv);
hconst->
type
=
new
TypeDecl
(Type::tUInt64);
hconst->
type
->
constant
=
true
;
auto
newCall =
static_cast
<ExprCallFunc*>(call->
clone
());
newCall->
arguments
.
insert
(newCall->
arguments
.
begin
() +
2
, hconst);
return
newCall;
}
else
{
err =
"
EID can't be an empty string
"
;
}
}
return
nullptr
;
}
//
note:
//
the hints will appear only on the non-transformed function!!!
string
aotArgumentPrefix
(ExprCallFunc *
/*
call
*/
,
int
argIndex)
override
{
return
"
/*arg-
"
+
to_string
(argIndex) +
"
-prefix*/
"
;
}
string
aotArgumentSuffix
(ExprCallFunc *
/*
call
*/
,
int
argIndex)
override
{
return
"
/*arg-
"
+
to_string
(argIndex) +
"
-suffix*/
"
;
}
};
struct
TestFunctionAnnotation
: FunctionAnnotation {
TestFunctionAnnotation
() : FunctionAnnotation(
"
test_function
"
) { }
virtual
bool
apply
(
const
FunctionPtr & fn, ModuleGroup &,
const
AnnotationArgumentList &, string & )
override
{
TextPrinter tp;
tp <<
"
test function: apply
"
<< fn->
describe
() <<
"
\n
"
;
return
true
;
}
virtual
bool
finalize
(
const
FunctionPtr & fn, ModuleGroup &,
const
AnnotationArgumentList &,
const
AnnotationArgumentList &, string & )
override
{
TextPrinter tp;
tp <<
"
test function: finalize
"
<< fn->
describe
() <<
"
\n
"
;
return
true
;
}
virtual
bool
apply
( ExprBlock * blk, ModuleGroup &,
const
AnnotationArgumentList &, string & )
override
{
TextPrinter tp;
tp <<
"
test function: apply to block at
"
<< blk->
at
.
describe
() <<
"
\n
"
;
return
true
;
}
virtual
bool
finalize
( ExprBlock * blk, ModuleGroup &,
const
AnnotationArgumentList &,
const
AnnotationArgumentList &, string & )
override
{
TextPrinter tp;
tp <<
"
test function: finalize block at
"
<< blk->
at
.
describe
() <<
"
\n
"
;
return
true
;
}
};
struct
EventRegistrator
: StructureAnnotation {
EventRegistrator
() : StructureAnnotation(
"
event
"
) {}
bool
touch
(
const
StructurePtr & st, ModuleGroup &
/*
libGroup
*/
,
const
AnnotationArgumentList &
/*
args
*/
, string &
/*
err
*/
)
override
{
st->
fields
.
emplace
(st->
fields
.
begin
(),
"
eventFlags
"
,
new
TypeDecl
(Type::tUInt16),
ExpressionPtr
(),
AnnotationArgumentList
(),
false
, st->
at
);
st->
fields
.
emplace
(st->
fields
.
begin
(),
"
eventSize
"
,
new
TypeDecl
(Type::tUInt16),
ExpressionPtr
(),
AnnotationArgumentList
(),
false
, st->
at
);
st->
fields
.
emplace
(st->
fields
.
begin
(),
"
eventType
"
,
new
TypeDecl
(Type::tUInt64),
ExpressionPtr
(),
AnnotationArgumentList
(),
false
, st->
at
);
return
true
;
}
bool
look
(
const
StructurePtr &
/*
st
*/
, ModuleGroup &
/*
libGroup
*/
,
const
AnnotationArgumentList &
/*
args
*/
, string &
/*
err
*/
)
override
{
return
true
;
}
};
#
if
defined(__APPLE__)
void
builtin_printw
(
char
* utf8string) {
fprintf
(stdout,
"
%s
"
, utf8string);
fflush
(stdout);
}
#
else
#
include
<
iostream
>
#
include
<
codecvt
>
#
include
<
locale
>
#
if
defined(_MSC_VER)
#
include
<
fcntl.h
>
#
include
<
io.h
>
#
endif
void
builtin_printw
(
char
* utf8string) {
std::wstring_convert<std::codecvt_utf8<
wchar_t
>> utf8_conv;
auto
outs = utf8_conv.
from_bytes
(utf8string);
#
if
defined(_MSC_VER)
_setmode
(
_fileno
(stdout), _O_U8TEXT);
#
else
std::wcout.
sync_with_stdio
(
false
);
std::wcout.
imbue
(
std::locale
(
"
en_US.utf8
"
));
#
endif
std::wcout << outs;
#
if
defined(_MSC_VER)
_setmode
(
_fileno
(stdout), _O_TEXT);
#
endif
}
#
endif
bool
tempArrayExample
(
const
TArray<
char
*> & arr,
const
TBlock<
void
, TTemporary<
const
TArray<
char
*>>> & blk, Context * context, LineInfoArg * at ) {
vec4f args[
1
];
args[
0
] = cast<
void
*>::
from
(&arr);
context->
invoke
(blk, args,
nullptr
, at);
return
(arr.
size
==
1
) && (
strcmp
(arr[
0
],
"
one
"
) ==
0
);
}
void
testPoint3Array
(
const
TBlock<
void
,
const
Point3Array> & blk, Context * context, LineInfoArg * at) {
Point3Array arr;
for
(
int32_t
x =
0
; x !=
10
; ++x) {
Point3 p;
p.
x
=
1
.
0f
;
p.
y
=
2
.
0f
;
p.
z
=
3
.
0f
;
arr.
push_back
(p);
}
vec4f args[
1
];
args[
0
] = cast<Point3Array *>::
from
(&arr);
context->
invoke
(blk, args,
nullptr
, at);
}
float2
test_abi_mad2
( float2 a, float2 b, float2 c ) {
return
v_add
(
v_mul
(a,b),c);
}
float3
test_abi_mad3
( float3 a, float3 b, float3 c ) {
return
v_add
(
v_mul
(a,b),c);
}
float4
test_abi_mad4
( float4 a, float4 b, float4 c ) {
return
v_add
(
v_mul
(a,b),c);
}
Func
test_abi_func
( Func a, Context * ctx ) {
bool
found =
false
;
for
(
int
i=
0
; i!=ctx->
getTotalFunctions
(); ++i ) {
if
( ctx->
getFunction
(i)==a.
PTR
) {
found =
true
;
break
;
}
}
if
( !found ) ctx->
throw_error
(
"
function not found
"
);
return
a;
}
TDim<
int32_t
,
10
>
testCMRES
( Context * __context__ )
{
TDim<
int32_t
,
10
> __a_rename_at_7;
das_zero
(__a_rename_at_7);
{
bool
__need_loop_8 =
true
;
//
j : int& -const
das_iterator<TDim<
int32_t
,
10
>>
__j_iterator
(__a_rename_at_7);
int32_t
* __j_rename_at_8;
__need_loop_8 = __j_iterator.
first
(__context__,(__j_rename_at_8)) && __need_loop_8;
for
( ; __need_loop_8 ; __need_loop_8 = __j_iterator.
next
(__context__,(__j_rename_at_8)) )
{
das_copy
((*__j_rename_at_8),
13
);
}
__j_iterator.
close
(__context__,(__j_rename_at_8));
};
return
das_auto_cast_ref<TDim<
int32_t
,
10
>>::
cast
(__a_rename_at_7);
}
void
testFooArray
(
const
TBlock<
void
,FooArray> & blk, Context * context, LineInfoArg * at) {
FooArray arr;
arr.
reserve
(
16
);
for
(
int32_t
x =
0
; x !=
10
; ++x) {
TestObjectFoo p;
p.
fooData
= x;
p.
foo_loop
=
nullptr
;
p.
lookAt
=
nullptr
;
arr.
push_back
(p);
}
vec4f args[
1
];
args[
0
] = cast<FooArray *>::
from
(&arr);
context->
invoke
(blk, args,
nullptr
, at);
}
void
tableMojo
( TTable<
char
*,
int
> & in,
const
TBlock<
void
,TTable<
char
*,
int
>> & block, Context * context, LineInfoArg * at ) {
vec4f args[
1
];
args[
0
] = cast<Table *>::
from
(&in);
context->
invoke
(block, args,
nullptr
, at);
}
class
Point3ArrayAnnotation
:
public
ManagedVectorAnnotation
<Point3Array> {
public:
Point3ArrayAnnotation
(ModuleLibrary & lib)
: ManagedVectorAnnotation<Point3Array>(
"
Point3Array
"
,lib) {
}
virtual
bool
isIndexMutable
(
const
TypeDeclPtr & )
const
override
{
return
true
; }
};
MAKE_TYPE_FACTORY
(BigEntityId,BigEntityId);
struct
BigEntityIdAnnotation
final
: das::ManagedValueAnnotation <BigEntityId> {
BigEntityIdAnnotation
(ModuleLibrary & mlib) : ManagedValueAnnotation (mlib,
"
BigEntityId
"
,
"
BigEntityId
"
) {}
virtual
void
walk
( das::DataWalker & walker,
void
* data )
override
{
if
( !walker.
reading
) {
const
BigEntityId * t = (BigEntityId *) data;
auto
value =
int4
(t->
value
[
0
], t->
value
[
1
], t->
value
[
2
], t->
value
[
3
]);
walker.
Int4
(value);
}
}
virtual
bool
isLocal
()
const
override
{
return
true
; }
virtual
bool
hasNonTrivialCtor
()
const
override
{
return
false
; }
virtual
bool
canBePlacedInContainer
()
const
override
{
return
true
; }
};
MAKE_TYPE_FACTORY
(EntityId,EntityId);
struct
EntityIdAnnotation
final
: das::ManagedValueAnnotation <EntityId> {
EntityIdAnnotation
(ModuleLibrary & mlib) : ManagedValueAnnotation (mlib,
"
EntityId
"
,
"
EntityId
"
) {}
virtual
void
walk
( das::DataWalker & walker,
void
* data )
override
{
if
( !walker.
reading
) {
const
EntityId * t = (EntityId *) data;
int32_t
eidV = t->
value
;
walker.
Int
(eidV);
}
}
virtual
bool
isLocal
()
const
override
{
return
true
; }
virtual
bool
hasNonTrivialCtor
()
const
override
{
return
false
; }
virtual
bool
canBePlacedInContainer
()
const
override
{
return
true
;}
};
void
tempArrayAliasExample
(
const
das::TArray<Point3> & arr,
const
das::TBlock<
void
, das::TTemporary<
const
das::TArray<Point3>>> & blk,
das::Context * context, LineInfoArg * at) {
vec4f args[
1
];
args[
0
] = cast<
void
*>::
from
(&arr);
context->
invoke
(blk, args,
nullptr
, at);
}
struct
FancyClassAnnotation
: ManagedStructureAnnotation <FancyClass,
true
,
true
> {
FancyClassAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
FancyClass
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(value)>(
"
value
"
);
}
virtual
bool
isLocal
()
const
override
{
return
true
; }
//
this is here so that we can make local variable and init with special c-tor
virtual
bool
canBePlacedInContainer
()
const
override
{
return
true
; }
//
this is here so that we can make array<FancyClass>
};
void
test_abi_lambda_and_function
( Lambda lambda, Func fn,
int32_t
lambdaSize, Context * context, LineInfoArg * lineinfo ) {
das_invoke_function<
void
>::
invoke
(context, lineinfo, fn, lambdaSize);
das_invoke_lambda<
void
>::
invoke
(context, lineinfo, lambda, lambdaSize);
}
MAKE_TYPE_FACTORY
(SceneNodeId,SceneNodeId);
struct
SceneNodeIdAnnotation
final
: das::ManagedValueAnnotation <SceneNodeId> {
SceneNodeIdAnnotation
(ModuleLibrary & mlib) : ManagedValueAnnotation (mlib,
"
SceneNodeId
"
,
"
SceneNodeId
"
) {}
virtual
void
walk
( das::DataWalker & walker,
void
* data )
override
{
if
( !walker.
reading
) {
const
SceneNodeId * t = (SceneNodeId *) data;
uint32_t
eidV = t->
id
;
walker.
UInt
(eidV);
}
}
virtual
bool
isLocal
()
const
override
{
return
true
; }
virtual
bool
hasNonTrivialCtor
()
const
override
{
return
false
; }
virtual
bool
canBePlacedInContainer
()
const
override
{
return
true
;}
};
SceneNodeId
__create_scene_node
() {
static
uint32_t
id =
1
;
return
SceneNodeId{id++};
}
struct
ByteCodeAnnotation
: ManagedStructureAnnotation <ByteCode> {
ByteCodeAnnotation
(ModuleLibrary & ml) : ManagedStructureAnnotation (
"
ByteCode
"
, ml) {
addField<
DAS_BIND_MANAGED_FIELD
(op_code)>(
"
op_code
"
);
addField<
DAS_BIND_MANAGED_FIELD
(high)>(
"
high
"
);
addField<
DAS_BIND_MANAGED_FIELD
(low)>(
"
low
"
);
}
};
//
Escape-analysis test sinks. Bound like `hash` (interop over vec4f) so any typed pointer flows in
//
with no cast. test_escape_pure is declared pure (the analysis may free the argument);
//
test_escape_keep retains the pointer in a global and is declared modifyExternal (must NOT free).
static
void
* g_escape_test_retained =
nullptr
;
vec4f
test_escape_pure
( Context &, SimNode_CallBase *, vec4f * ) {
return
cast<
int32_t
>::
from
(
0
);
}
vec4f
test_escape_keep
( Context &, SimNode_CallBase *, vec4f * args ) {
g_escape_test_retained = cast<
void
*>::
to
(args[
0
]);
return
v_zero
();
}
//
reads the first int field of the last pointer handed to test_escape_keep; lets a .das soundness
//
test confirm a retained (escaping) pointer was not wrongly freed and reused.
int32_t
test_escape_retained_first_int
() {
return
g_escape_test_retained ? *(
int32_t
*)g_escape_test_retained : -
1
;
}
Module_UnitTest::Module_UnitTest
() : Module(
"
UnitTest
"
) {
ModuleLibrary
lib
(
this
);
lib.
addBuiltInModule
();
addBuiltinDependency
(lib,
Module::require
(
"
math
"
));
addEnumTest
(lib);
//
options
options[
"
unit_test
"
] = Type::tFloat;
//
constant
addConstant
(*
this
,
"
UNIT_TEST_CONSTANT
"
,
0x12345678
);
//
structure annotations
addAnnotation
(
new
CheckRange
());
//
dummy type example
addAnnotation
(
new
DummyTypeAnnotation
(
"
SomeDummyType
"
,
"
SomeDummyType
"
,
sizeof
(SomeDummyType),
alignof
(SomeDummyType)));
//
register types
addAnnotation
(
new
TestObjectNotNullPtrAnnotation
(lib));
addAnnotation
(
new
TestObjectNotLocalAnnotation
(lib));
auto
fooann =
new
TestObjectFooAnnotation
(lib);
addAnnotation
(fooann);
initRecAnnotation
(fooann,lib);
addAnnotation
(
new
TestObjectBarAnnotation
(lib));
//
smart object recursive type
auto
tosa =
new
TestObjectSmartAnnotation
(lib);
addAnnotation
(tosa);
initRecAnnotation
(tosa, lib);
//
events
addAnnotation
(
new
EventRegistrator
());
//
test
addAnnotation
(
new
TestFunctionAnnotation
());
//
point3 array
addAlias
(typeFactory<Point3>::
make
(lib));
addVectorAnnotation<Point3Array>(
this
,lib,
new
Point3ArrayAnnotation
(lib));
addCtorAndUsing<Point3Array>(*
this
, lib,
"
Point3Array
"
,
"
Point3Array
"
);
addExtern<
DAS_BIND_FUN
(testPoint3Array)>(*
this
, lib,
"
testPoint3Array
"
,
SideEffects::modifyExternal,
"
testPoint3Array
"
);
addExtern<
DAS_BIND_FUN
(testCMRES),SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
testCMRES
"
,
SideEffects::modifyExternal,
"
testCMRES
"
);
//
abi tests. We use it in JIT.
addExtern<
DAS_BIND_FUN
(test_abi_mad2) >(*
this
,lib,
"
test_abi_mad
"
,SideEffects::worstDefault,
"
test_abi_mad2
"
)
->
args
({
"
a
"
,
"
b
"
,
"
c
"
});
addExtern<
DAS_BIND_FUN
(test_abi_mad3) >(*
this
,lib,
"
test_abi_mad
"
,SideEffects::worstDefault,
"
test_abi_mad3
"
)
->
args
({
"
a
"
,
"
b
"
,
"
c
"
});
addExtern<
DAS_BIND_FUN
(test_abi_mad4) >(*
this
,lib,
"
test_abi_mad
"
,SideEffects::worstDefault,
"
test_abi_mad4
"
)
->
args
({
"
a
"
,
"
b
"
,
"
c
"
});
addExtern<
DAS_BIND_FUN
(test_abi_func) >(*
this
,lib,
"
test_abi_func
"
,SideEffects::worstDefault,
"
test_abi_func
"
)
->
args
({
"
fn
"
,
"
context
"
});
//
foo array
addExtern<
DAS_BIND_FUN
(testFooArray)>(*
this
, lib,
"
testFooArray
"
,
SideEffects::modifyExternal,
"
testFooArray
"
);
addExtern<
DAS_BIND_FUN
(set_foo_data)>(*
this
, lib,
"
set_foo_data
"
,
das::SideEffects::modifyArgument,
"
set_foo_data
"
);
//
utf8 print
addExtern<
DAS_BIND_FUN
(builtin_printw)>(*
this
, lib,
"
printw
"
,
SideEffects::modifyExternal,
"
builtin_printw
"
);
//
register function
addEquNeq<TestObjectFoo>(*
this
, lib);
addExtern<
DAS_BIND_FUN
(complex_bind)>(*
this
, lib,
"
complex_bind
"
,
SideEffects::modifyExternal,
"
complex_bind
"
);
addInterop<new_and_init,
void
*,vec4f>(*
this
, lib,
"
new_and_init
"
,
SideEffects::none,
"
new_and_init
"
);
addInterop<test_escape_pure,
int32_t
,vec4f>(*
this
, lib,
"
test_escape_pure
"
,
SideEffects::none,
"
test_escape_pure
"
)->
arg
(
"
ptr
"
);
addInterop<test_escape_keep,
void
,vec4f>(*
this
, lib,
"
test_escape_keep
"
,
SideEffects::modifyExternal,
"
test_escape_keep
"
)->
arg
(
"
ptr
"
);
addExtern<
DAS_BIND_FUN
(test_escape_retained_first_int)>(*
this
, lib,
"
test_escape_retained_first_int
"
,
SideEffects::modifyExternal,
"
test_escape_retained_first_int
"
);
addExtern<
DAS_BIND_FUN
(get_screen_dimensions)>(*
this
, lib,
"
get_screen_dimensions
"
,
SideEffects::none,
"
get_screen_dimensions
"
);
addExtern<
DAS_BIND_FUN
(test_das_string)>(*
this
, lib,
"
test_das_string
"
,
SideEffects::modifyExternal,
"
test_das_string
"
);
addExtern<
DAS_BIND_FUN
(testPipedDefaults)>(*
this
, lib,
"
testPipedDefaults
"
,
SideEffects::invoke,
"
testPipedDefaults
"
)
->
args
({
"
a
"
,
"
b
"
,
"
blk
"
,
"
context
"
,
"
at
"
})
->
arg_init
(
1
,
new
ExprConstFloat
(
3
.
125f
));
addExtern<
DAS_BIND_FUN
(testFoo)>(*
this
, lib,
"
testFoo
"
,
SideEffects::modifyArgument,
"
testFoo
"
);
addExtern<
DAS_BIND_FUN
(testAdd)>(*
this
, lib,
"
testAdd
"
,
SideEffects::modifyArgument,
"
testAdd
"
);
addExtern<
DAS_BIND_FUN
(getSamplePoint3)>(*
this
, lib,
"
getSamplePoint3
"
,
SideEffects::modifyExternal,
"
getSamplePoint3
"
);
addExtern<
DAS_BIND_FUN
(doubleSamplePoint3)>(*
this
, lib,
"
doubleSamplePoint3
"
,
SideEffects::none,
"
doubleSamplePoint3
"
);
addExtern<
DAS_BIND_FUN
(project_to_nearest_navmesh_point)>(*
this
, lib,
"
project_to_nearest_navmesh_point
"
,
SideEffects::modifyArgument,
"
project_to_nearest_navmesh_point
"
);
addExtern<
DAS_BIND_FUN
(getPtr)>(*
this
, lib,
"
getPtr
"
,
SideEffects::modifyExternal,
"
getPtr
"
);
/*
addExtern<DAS_BIND_FUN(makeDummy)>(*this, lib, "makeDummy", SideEffects::none, "makeDummy");
*/
addExtern<
DAS_BIND_FUN
(makeDummy), SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
makeDummy
"
,
SideEffects::none,
"
makeDummy
"
);
addExtern<
DAS_BIND_FUN
(makeDummy), SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
makeTempDummy
"
,
SideEffects::none,
"
makeDummy
"
)->
setTempResult
();
addExtern<
DAS_BIND_FUN
(takeDummy)>(*
this
, lib,
"
takeDummy
"
,
SideEffects::none,
"
takeDummy
"
);
//
register Cpp alignment functions
addExtern<
DAS_BIND_FUN
(CppS1Size)>(*
this
, lib,
"
CppS1Size
"
,
SideEffects::modifyExternal,
"
CppS1Size
"
);
addExtern<
DAS_BIND_FUN
(CppS2Size)>(*
this
, lib,
"
CppS2Size
"
,
SideEffects::modifyExternal,
"
CppS2Size
"
);
addExtern<
DAS_BIND_FUN
(CppS2DOffset)>(*
this
, lib,
"
CppS2DOffset
"
,
SideEffects::modifyExternal,
"
CppS2DOffset
"
);
//
register CheckEid functions
addExtern<
DAS_BIND_FUN
(CheckEidHint)>(*
this
, lib,
"
CheckEid
"
,
SideEffects::none,
"
CheckEidHint
"
);
auto
ceid = addExtern<
DAS_BIND_FUN
(CheckEid)>(*
this
, lib,
"
CheckEid
"
, SideEffects::none,
"
CheckEid
"
);
auto
ceid_decl =
new
AnnotationDeclaration
();
ceid_decl->
annotation
=
new
CheckEidFunctionAnnotation
();
ceid->
annotations
.
push_back
(ceid_decl);
//
register CheckEid2 functoins and macro
addExtern<
DAS_BIND_FUN
(CheckEidHint)>(*
this
, lib,
"
CheckEid2
"
,
SideEffects::modifyExternal,
"
CheckEidHint
"
);
addExtern<
DAS_BIND_FUN
(CheckEid)>(*
this
, lib,
"
CheckEid2
"
,
SideEffects::modifyExternal,
"
CheckEid
"
);
addExtern<
DAS_BIND_FUN
(CheckEid)>(*
this
, lib,
"
CheckEid3
"
,
SideEffects::modifyExternal,
"
CheckEid
"
);
//
extra tests
addExtern<
DAS_BIND_FUN
(start_effect)>(*
this
, lib,
"
start_effect
"
,
SideEffects::modifyExternal,
"
start_effect
"
);
addExtern<
DAS_BIND_FUN
(tempArrayExample)>(*
this
, lib,
"
temp_array_example
"
,
SideEffects::modifyExternal,
"
tempArrayExample
"
);
addExtern<
DAS_BIND_FUN
(tempArrayAliasExample)>(*
this
, lib,
"
temp_array_alias_example
"
,
SideEffects::invoke,
"
tempArrayAliasExample
"
);
//
ptr2ref
addExtern<
DAS_BIND_FUN
(fooPtr2Ref),SimNode_ExtFuncCallRef>(*
this
, lib,
"
fooPtr2Ref
"
,
SideEffects::none,
"
fooPtr2Ref
"
);
//
compiled functions
appendCompiledFunctions
();
//
add sample variant type
addAlias
(typeFactory<SampleVariant>::
make
(lib));
addExtern<
DAS_BIND_FUN
(makeSampleI), SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
makeSampleI
"
,
SideEffects::none,
"
makeSampleI
"
);
addExtern<
DAS_BIND_FUN
(makeSampleF), SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
makeSampleF
"
,
SideEffects::none,
"
makeSampleF
"
);
addExtern<
DAS_BIND_FUN
(makeSampleS), SimNode_ExtFuncCallAndCopyOrMove>(*
this
, lib,
"
makeSampleS
"
,
SideEffects::none,
"
makeSampleS
"
);
//
smart ptr
addExtern<
DAS_BIND_FUN
(getTotalTestObjectSmart)>(*
this
, lib,
"
getTotalTestObjectSmart
"
,
SideEffects::accessExternal,
"
getTotalTestObjectSmart
"
);
addExtern<
DAS_BIND_FUN
(makeTestObjectSmart)>(*
this
, lib,
"
makeTestObjectSmart
"
,
SideEffects::modifyExternal,
"
makeTestObjectSmart
"
);
addExtern<
DAS_BIND_FUN
(countTestObjectSmart)>(*
this
, lib,
"
countTestObjectSmart
"
,
SideEffects::none,
"
countTestObjectSmart
"
);
//
div
addExtern<
DAS_BIND_FUN
(testGetDiv)>(*
this
, lib,
"
testGetDiv
"
,
SideEffects::none,
"
testGetDiv
"
);
addExtern<
DAS_BIND_FUN
(testGetNan)>(*
this
, lib,
"
testGetNan
"
,
SideEffects::none,
"
testGetNan
"
);
//
call line
addExtern<
DAS_BIND_FUN
(testCallLine)>(*
this
, lib,
"
testCallLine
"
,
SideEffects::modifyExternal,
"
testCallLine
"
);
//
table mojo
addExtern<
DAS_BIND_FUN
(tableMojo)>(*
this
, lib,
"
tableMojo
"
,
SideEffects::modifyExternal,
"
tableMojo
"
);
//
BigEntityId
addAnnotation
(
new
BigEntityIdAnnotation
(lib));
//
EntityId
addAnnotation
(
new
EntityIdAnnotation
(lib));
addExtern<
DAS_BIND_FUN
(make_invalid_id)>(*
this
, lib,
"
make_invalid_id
"
,
SideEffects::none,
"
make_invalid_id
"
);
addExtern<
DAS_BIND_FUN
(eidToInt)>(*
this
, lib,
"
int
"
,
SideEffects::none,
"
eidToInt
"
);
addExtern<
DAS_BIND_FUN
(intToEid)>(*
this
, lib,
"
EntityId
"
,
SideEffects::none,
"
intToEid
"
);
//
FancyClass
addAnnotation
(
new
FancyClassAnnotation
(lib));
addCtorAndUsing<FancyClass>(*
this
,lib,
"
FancyClass
"
,
"
FancyClass
"
);
addCtorAndUsing<FancyClass,
int32_t
,
int32_t
>(*
this
,lib,
"
FancyClass
"
,
"
FancyClass
"
);
addExtern<
DAS_BIND_FUN
(deleteFancyClass)>(*
this
, lib,
"
deleteFancyClass
"
,
SideEffects::modifyArgumentAndExternal,
"
deleteFancyClassDummy
"
);
//
member function
using
method_hitMe =
DAS_CALL_MEMBER
(TestObjectFoo::hitMe);
addExtern<
DAS_CALL_METHOD
(method_hitMe) >(*
this
, lib,
"
hit_me
"
, SideEffects::modifyArgument,
DAS_CALL_MEMBER_CPP
(TestObjectFoo::hitMe));
//
abit
addExtern<
DAS_BIND_FUN
(test_abi_lambda_and_function)>(*
this
, lib,
"
test_abi_lambda_and_function
"
,
SideEffects::invokeAndAccessExternal,
"
test_abi_lambda_and_function
"
);
//
SceneNodeId
addAnnotation
(
new
SceneNodeIdAnnotation
(lib));
addExtern<
DAS_BIND_FUN
(__create_scene_node)>(*
this
, lib,
"
__create_scene_node
"
,
SideEffects::none,
"
__create_scene_node
"
);
//
byte code interpreter
addEnumeration
(
new
EnumerationOpCode
());
addAnnotation
(
new
ByteCodeAnnotation
(lib));
addExtern<
DAS_BIND_FUN
(evalByteCode)>(*
this
, lib,
"
evalByteCode
"
,
SideEffects::modifyArgumentAndAccessExternal,
"
evalByteCode
"
);
//
and verify
verifyAotReady
();
}
ModuleAotType
Module_UnitTest::aotRequire
( TextWriter & tw )
const
{
tw <<
"
#include
\"
unitTest.h
\"\n
"
;
return
ModuleAotType::cpp;
}
#
include
"
unit_test.das.inc
"
bool
Module_UnitTest::appendCompiledFunctions
() {
return
compileBuiltinModule
(
this
,
"
unit_test.das
"
,unit_test_das,
sizeof
(unit_test_das));
}
REGISTER_DYN_MODULE
(Module_UnitTest, Module_UnitTest);
REGISTER_MODULE
(Module_UnitTest);
Back
|
FazBrowse Home
|
New Git URL