diff --git a/autotest/PPTest/PPTest.cpp b/autotest/PPTest/PPTest.cpp new file mode 100644 index 000000000..b8016d5c7 --- /dev/null +++ b/autotest/PPTest/PPTest.cpp @@ -0,0 +1,27 @@ +#include +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + String path = GetDataFile("test.in"); + PPSync(GetFileFolder(path)); + + Cpp cpp; + FileIn in(path); + cpp.Preprocess(path, in, path); + + String s = cpp.output; + String opath = GetDataFile("test.out"); + + LOG("======================"); + LOG(cpp.output); + +#ifdef flagSAVE + SaveFile(opath, s); +#else + ASSERT(LoadFile(opath) == s); +#endif + LOG("===================== OK"); +} diff --git a/autotest/PPTest/PPTest.upp b/autotest/PPTest/PPTest.upp new file mode 100644 index 000000000..30b503cc7 --- /dev/null +++ b/autotest/PPTest/PPTest.upp @@ -0,0 +1,14 @@ +uses + Core, + CppBase; + +file + PPTest.cpp, + test.in, + test.out, + help.in; + +mainconfig + "" = "", + "" = "SAVE"; + diff --git a/autotest/PPTest/help.in b/autotest/PPTest/help.in new file mode 100644 index 000000000..84d35d650 --- /dev/null +++ b/autotest/PPTest/help.in @@ -0,0 +1,127 @@ +#define COMBINE__(a, b) a##b +#define COMBINE(a, b) COMBINE__(a, b) + +#define COMBINE3__(a, b, c) a##b##c +#define COMBINE3(a, b, c) COMBINE3__(a, b, c) + +#define COMBINE4__(a, b, c, d) a##b##c##d +#define COMBINE4(a, b, c, d) COMBINE4__(a, b, c, d) + +#define COMBINE5__(a, b, c, d, e) a##b##c##d##e +#define COMBINE5(a, b, c, d, e) COMBINE5__(a, b, c, d, e) + +#define _cm_ , + +#define __countof(a) int(sizeof(a) / sizeof(a[0])) + +#define __Expand1(x) x(1) +#define __Expand2(x) __Expand1(x) x(2) +#define __Expand3(x) __Expand2(x) x(3) +#define __Expand4(x) __Expand3(x) x(4) +#define __Expand5(x) __Expand4(x) x(5) + +#define __List1(x) x(1) +#define __List2(x) __List1(x), x(2) +#define __List3(x) __List2(x), x(3) +#define __List4(x) __List3(x), x(4) +#define __List5(x) __List4(x), x(5) + +#define E__p(I) p##I + +#define MK__s__(x) s__s##x +#define MK__s_(x) MK__s__(x) + +// #define MK__s MK__s_(__LINE__) + +#define MK__s MK__s_(COMBINE3(BLITZ_INDEX__, _, __LINE__)) + +#define INITBLOCK \ +static void COMBINE(MK__s, _fn)(); static UPP::Callinit MK__s(COMBINE(MK__s, _fn), __FILE__, __LINE__); \ +static void COMBINE(MK__s, _fn)() + + +//--------------------------------------------------- + +#define E__NFValue(I) const Value& COMBINE(p, I) +#define E__NFBody(I) \ +String Format(const char *fmt, __List##I(E__NFValue)); +__Expand5(E__NFBody) + +// ============= + +INITBLOCK { + Value::SvoRegister("Color"); +} + +// ============= + + + #define max (a, b) (a < b ? b : a) + +max(12, 23) + +max (A, B) + +#undef max + +#define max(a, b) (a < b ? b : a) + +max(12, 23) + +max (A, B) + +// ============= + +#define macro something // comment + +macro +something +//$- comment + +#define mm(a, b, c, d) (d) [c] {b} + +mm(1, 2, 3, 4) + +mm(1, 2, +3, 4) + +mm(1, +2, +3, +4 +) + +// ============= + +#define MACRO(x) 123+x + +MACRO( +x +) + +MACRO(x +) + +MACRO(x) + + MACRO(x) + + MACRO(x +) + +// ============= + +#undef _STCONS + + #define _STCONS(ty, name, val) static const ty name = (ty)(val) + + _STCONS(float_denorm_style, has_denorm, denorm_absent); + + + +#define InterlockedIncrement16 _InterlockedIncrement16 + +SHORT +InterlockedIncrement16 ( + SHORT volatile *Addend +); diff --git a/autotest/PPTest/init b/autotest/PPTest/init new file mode 100644 index 000000000..3b2d60dcc --- /dev/null +++ b/autotest/PPTest/init @@ -0,0 +1,5 @@ +#ifndef _PPTest_icpp_init_stub +#define _PPTest_icpp_init_stub +#include "Core/init" +#include "CppBase/init" +#endif diff --git a/autotest/PPTest/test.in b/autotest/PPTest/test.in new file mode 100644 index 000000000..84d35d650 --- /dev/null +++ b/autotest/PPTest/test.in @@ -0,0 +1,127 @@ +#define COMBINE__(a, b) a##b +#define COMBINE(a, b) COMBINE__(a, b) + +#define COMBINE3__(a, b, c) a##b##c +#define COMBINE3(a, b, c) COMBINE3__(a, b, c) + +#define COMBINE4__(a, b, c, d) a##b##c##d +#define COMBINE4(a, b, c, d) COMBINE4__(a, b, c, d) + +#define COMBINE5__(a, b, c, d, e) a##b##c##d##e +#define COMBINE5(a, b, c, d, e) COMBINE5__(a, b, c, d, e) + +#define _cm_ , + +#define __countof(a) int(sizeof(a) / sizeof(a[0])) + +#define __Expand1(x) x(1) +#define __Expand2(x) __Expand1(x) x(2) +#define __Expand3(x) __Expand2(x) x(3) +#define __Expand4(x) __Expand3(x) x(4) +#define __Expand5(x) __Expand4(x) x(5) + +#define __List1(x) x(1) +#define __List2(x) __List1(x), x(2) +#define __List3(x) __List2(x), x(3) +#define __List4(x) __List3(x), x(4) +#define __List5(x) __List4(x), x(5) + +#define E__p(I) p##I + +#define MK__s__(x) s__s##x +#define MK__s_(x) MK__s__(x) + +// #define MK__s MK__s_(__LINE__) + +#define MK__s MK__s_(COMBINE3(BLITZ_INDEX__, _, __LINE__)) + +#define INITBLOCK \ +static void COMBINE(MK__s, _fn)(); static UPP::Callinit MK__s(COMBINE(MK__s, _fn), __FILE__, __LINE__); \ +static void COMBINE(MK__s, _fn)() + + +//--------------------------------------------------- + +#define E__NFValue(I) const Value& COMBINE(p, I) +#define E__NFBody(I) \ +String Format(const char *fmt, __List##I(E__NFValue)); +__Expand5(E__NFBody) + +// ============= + +INITBLOCK { + Value::SvoRegister("Color"); +} + +// ============= + + + #define max (a, b) (a < b ? b : a) + +max(12, 23) + +max (A, B) + +#undef max + +#define max(a, b) (a < b ? b : a) + +max(12, 23) + +max (A, B) + +// ============= + +#define macro something // comment + +macro +something +//$- comment + +#define mm(a, b, c, d) (d) [c] {b} + +mm(1, 2, 3, 4) + +mm(1, 2, +3, 4) + +mm(1, +2, +3, +4 +) + +// ============= + +#define MACRO(x) 123+x + +MACRO( +x +) + +MACRO(x +) + +MACRO(x) + + MACRO(x) + + MACRO(x +) + +// ============= + +#undef _STCONS + + #define _STCONS(ty, name, val) static const ty name = (ty)(val) + + _STCONS(float_denorm_style, has_denorm, denorm_absent); + + + +#define InterlockedIncrement16 _InterlockedIncrement16 + +SHORT +InterlockedIncrement16 ( + SHORT volatile *Addend +); diff --git a/autotest/PPTest/test.out b/autotest/PPTest/test.out new file mode 100644 index 000000000..d5e4e1854 --- /dev/null +++ b/autotest/PPTest/test.out @@ -0,0 +1,127 @@ +#define COMBINE__(a, b) a##b +#define COMBINE(a, b) COMBINE__(a, b) + +#define COMBINE3__(a, b, c) a##b##c +#define COMBINE3(a, b, c) COMBINE3__(a, b, c) + +#define COMBINE4__(a, b, c, d) a##b##c##d +#define COMBINE4(a, b, c, d) COMBINE4__(a, b, c, d) + +#define COMBINE5__(a, b, c, d, e) a##b##c##d##e +#define COMBINE5(a, b, c, d, e) COMBINE5__(a, b, c, d, e) + +#define _cm_ , + +#define __countof(a) int(sizeof(a) / sizeof(a[0])) + +#define __Expand1(x) x(1) +#define __Expand2(x) __Expand1(x) x(2) +#define __Expand3(x) __Expand2(x) x(3) +#define __Expand4(x) __Expand3(x) x(4) +#define __Expand5(x) __Expand4(x) x(5) + +#define __List1(x) x(1) +#define __List2(x) __List1(x), x(2) +#define __List3(x) __List2(x), x(3) +#define __List4(x) __List3(x), x(4) +#define __List5(x) __List4(x), x(5) + +#define E__p(I) p##I + +#define MK__s__(x) s__s##x +#define MK__s_(x) MK__s__(x) + +// #define MK__s MK__s_(__LINE__) + +#define MK__s MK__s_(COMBINE3(BLITZ_INDEX__, _, __LINE__)) + +#define INITBLOCK static void COMBINE(MK__s, _fn)(); static UPP::Callinit MK__s(COMBINE(MK__s, _fn), __FILE__, __LINE__); static void COMBINE(MK__s, _fn)() + + + + +//--------------------------------------------------- + +#define E__NFValue(I) const Value& COMBINE(p, I) +#define E__NFBody(I) String Format(const char *fmt, __List##I(E__NFValue)); + +String Format(const char *fmt, const Value& p1); String Format(const char *fmt, const Value& p1, const Value& p2); String Format(const char *fmt, const Value& p1, const Value& p2, const Value& p3); String Format(const char *fmt, const Value& p1, const Value& p2, const Value& p3, const Value& p4); String Format(const char *fmt, const Value& p1, const Value& p2, const Value& p3, const Value& p4, const Value& p5); + +// ============= + + static void s__sBLITZ_INDEX_____LINE___fn(); static UPP::Callinit  s__sBLITZ_INDEX_____LINE__(s__sBLITZ_INDEX_____LINE___fn, __FILE__, __LINE__); static void s__sBLITZ_INDEX_____LINE___fn() { + Value::SvoRegister("Color"); +} + +// ============= + + + #define max (a, b) (a < b ? b : a) + + (a, b) (a < b ? b : a)(12, 23) + + (a, b) (a < b ? b : a) (A, B) + +#undef max + +#define max(a, b) (a < b ? b : a) + +(12 < 23 ? 23 : 12) + +(A < B ? B : A) + +// ============= + +#define macro something // comment + + something +something +//$- comment + +#define mm(a, b, c, d) (d) [c] {b} + +(4) [3] {2} <1> + + +(4) [3] {2} <1> + + + + + +(4) [3] {2} <1> + +// ============= + +#define MACRO(x) 123+x + + + +123+x + + +123+x + +123+x + + 123+x + + + 123+x + +// ============= + +#undef _STCONS + + #define _STCONS(ty, name, val) static const ty name = (ty)(val) + + static const float_denorm_style has_denorm = (float_denorm_style)(denorm_absent); + + + +#define InterlockedIncrement16 _InterlockedIncrement16 + +SHORT + _InterlockedIncrement16 ( + SHORT volatile *Addend +);