1#version 450 2 3// side test verifies multiple rounds of argument expansion 4#define bear SecondExpansion 5#define mmmB bear 6#define mmmA(a) a 7int mmmA(mmmB); // mmmB -> bear, and then in mmmA(), bear -> SecondExpansion 8 9// pasting skips the first round of expansion 10#define mmcatmmdog PostPasteExpansion 11#define mmcat cat 12#define mmdog dog 13#define mmp(a,b) a## b 14int mmp(mmcat, mmdog); // mmcat/mmdog not expanded, mmcatmmdog -> PostPasteExpansion 15 16// multi-token pre 17#define mmtokpastepre(a) a##27 18mmtokpastepre(float foo); // should declare "float foo27;" 19 20// multi-token post 21#define mmtokpastepost(a) uni ##a 22mmtokpastepost(form float foo155); // should declare "uniform float foo155;" 23 24// non-first argument 25#define foo ShouldntExpandToThis 26#define semi ; 27#define bothpaste(a,b) a##b 28float bothpaste(foo, 719); // should declare "float foo719;" 29#define secpaste(a,b) a bar ## b 30secpaste(uniform float, foo semi) // should declare "uniform float barfoo;" 31 32// no args 33#define noArg fl##oat 34noArg argless; 35 36// bad location 37#define bad1 ## float 38bad1 dc1; 39#define bad2 float ## 40bad2 dc2; 41 42// multiple ## 43#define multiPaste(a, b, c) a##or##b flo##at foo##c 44multiPaste(unif, m, 875); 45 46// too long 47#define simplePaste(a,b) a##b 48// 1020 + 5 characters 49float simplePaste(ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345, 12345); 50 51// non-identifiers 52int a = simplePaste(11,12); 53 54// operators 55#define MAKE_OP(L, R) L ## R 56const int aop = 10; 57const int bop = 4; 58int cop = aop MAKE_OP(<, <) bop; 59bool dop = aop MAKE_OP(!,=) bop; 60 61#define MAKE_OP3(L, M, R) L ## M ## R 62 63void foo() 64{ 65 int e = 16; 66 e MAKE_OP3(>,>,=) 2; 67 68 // recovery from bad op 69 bool f = e MAKE_OP(>,!) 5; 70} 71 72// arguments: should make 'uniform int argPaste2;' 73#define M_NEST(q) int q 74#define M_OUTER(p) M_NEST(p##2) 75uniform M_OUTER(argPaste); 76// should make 'uniform int argPaste20suff;' 77#define M_NEST2(q) int q ## suff 78#define M_OUTER2(p) M_NEST2(p ## 20) 79uniform M_OUTER2(argPaste); 80 81#define rec(x)## 82rec(rec()) 83 84#define bax(bay) 85#define baz bax(/##) 86baz 87