yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Tim FoleyFix for a macro expansion bug (#1192)922cd543d

master
1.1 KiB45 linesraw
1//TEST(compute):SIMPLE:
2
3// Test for correct recursive macro behavior. In particular: 
4
5// The letter of the spec is that we should macro expand
6// each argument *before* substitution, and then go and
7// macro-expand the substituted body. This means that we
8// can invoke a macro as part of an argument to an
9// invocation of the same macro:
10//
11//     FOO( 1, FOO(22, 2, 2), 333 );
12
13// Also in the case on NO_EXPAND, it will not be expanded in the substitution. 
14
15#define ARG_EXPAND(x) ( x )
16
17// This macro should expand to NO_EXPAND(int 'a'), and not multiply invoke NO_EXPAND, because
18// one the args have been expanded.
19#define NO_EXPAND(a) NO_EXPAND(int a)
20
21// Should expand to int NO_EXPAND(int b)
22int NO_EXPAND(b)
23{
24    return b + ARG_EXPAND(ARG_EXPAND(1));
25}
26
27// The same issue can arise for object-like macros and not
28// just function-like, so we will test that case here as well.
29
30int objectLikeMacroTest( int REC )
31{
32#define REC REC
33
34	return REC;	
35}
36
37// We also need to check the case where macros are
38// mutually, rather than directly, recursive
39
40int mutuallyRecursiveMacroTest( int XYZ )
41{
42	#define ABC XYZ
43	#define XYZ ABC
44	return XYZ;
45}