diff --git a/uppdev/CompressedSerialize/CompressedSerialize.cpp b/uppdev/CompressedSerialize/CompressedSerialize.cpp index 7374c8aec..29747bef2 100644 --- a/uppdev/CompressedSerialize/CompressedSerialize.cpp +++ b/uppdev/CompressedSerialize/CompressedSerialize.cpp @@ -1,4 +1,5 @@ #include +#include using namespace Upp; @@ -16,21 +17,16 @@ CONSOLE_APP_MAIN FileOut fout(path); fout.Put("COMPRESSED"); int64 pos = fout.GetPos(); - fout.Put64le(pos); - Zlib zlib; + Lz4 zlib; OutFilterStream out(fout, zlib); zlib.Compress(); out % h; - fout.Seek(pos); - DDUMP(out.GetInCount()); - DDUMP(out.GetCount()); - fout.Put64le(out.GetInCount()); + int ob = out.GetPos(); out.Close(); - DDUMP(out.GetCount()); - DDUMP(out.GetInCount()); + fout.Seek(pos); + fout.Put64le(out.GetPos()); } - { String h2; @@ -42,7 +38,7 @@ CONSOLE_APP_MAIN return; int sz = fin.Get64le(); DDUMP(sz); - Zlib zlib; + Lz4 zlib; InFilterStream in(fin, zlib); in.SetSize(sz); zlib.Decompress(); diff --git a/uppdev/CompressedSerialize/CompressedSerialize.upp b/uppdev/CompressedSerialize/CompressedSerialize.upp index 39b5261c7..d14f0a1da 100644 --- a/uppdev/CompressedSerialize/CompressedSerialize.upp +++ b/uppdev/CompressedSerialize/CompressedSerialize.upp @@ -1,5 +1,6 @@ uses - Core; + Core, + plugin/lz4; file CompressedSerialize.cpp; diff --git a/uppdev/CompressedSerialize/init b/uppdev/CompressedSerialize/init index 46a0c7c5e..0d03a817f 100644 --- a/uppdev/CompressedSerialize/init +++ b/uppdev/CompressedSerialize/init @@ -1,4 +1,5 @@ #ifndef _CompressedSerialize_icpp_init_stub #define _CompressedSerialize_icpp_init_stub #include "Core/init" +#include "plugin/lz4/init" #endif diff --git a/uppdev/PainterLine/PainterLine.upp b/uppdev/PainterLine/PainterLine.upp index 90acec41c..744e02d2d 100644 --- a/uppdev/PainterLine/PainterLine.upp +++ b/uppdev/PainterLine/PainterLine.upp @@ -8,5 +8,5 @@ file PainterLine.lay; mainconfig - "" = "GUI"; + "" = "GUI PRECLIP"; diff --git a/uppdev/PainterLine/main.cpp b/uppdev/PainterLine/main.cpp index 839c45255..c9603ca99 100644 --- a/uppdev/PainterLine/main.cpp +++ b/uppdev/PainterLine/main.cpp @@ -6,12 +6,12 @@ using namespace Upp; struct PainterLine : public TopWindow { int wd; Point tg; - +/* virtual Image CursorImage(Point p, dword keyflags) { return Null; } - +*/ virtual void LeftDown(Point p, dword keyflags) { wd = wd + 1; if(wd > 10) @@ -26,11 +26,15 @@ struct PainterLine : public TopWindow { } virtual void Paint(Draw& w) { + w.DrawRect(GetSize(), White()); { - DrawPainter g(w, GetSize()/*, MODE_NOAA*/); - g.DrawRect(GetSize(), White()); - g.DrawRect(100, 100, 200, 150, LtGray()); - g.DrawLine(100, 100, tg.x, tg.y, wd); + ImageBuffer ib(100, 100); + BufferPainter sw(ib); + sw.PreClip(); + sw.Scale(1.1); + sw.Clear(White()); + sw.Move(-50, -50).Line(tg.x, tg.y).Dash("10 5").Stroke(5, Blue()); + w.DrawImage(50, 50, ib); } w.Offset(0, 200); w.DrawRect(100, 100, 200, 150, LtGray()); diff --git a/uppdev/PainterTest/main.cpp b/uppdev/PainterTest/main.cpp index 392a0378c..a41395884 100644 --- a/uppdev/PainterTest/main.cpp +++ b/uppdev/PainterTest/main.cpp @@ -5,13 +5,14 @@ using namespace Upp; struct PainterTest : public TopWindow { virtual void Paint(Draw& w) { - DrawPainter p(w, GetSize()/*, MODE_NOAA*/); + DrawPainter p(w, GetSize()); p.Clear(White()); - p.Move(100, 100); - p.Line(200, 100); - p.Line(300, 300); - p.Fill(Pointf(100, 100), Blue(), Pointf(300, 300), Red()); + p.RoundedRectangle(0, 0, 300, 300, 40, 15); + p.Fill(Pointf(0.5, 0.3), Blue(), Red(), + Xform2D::Scale(150, 100) * Xform2D::Translation(150, 150), + GRADIENT_PAD); + } }; @@ -19,4 +20,3 @@ GUI_APP_MAIN { PainterTest().Run(); } - diff --git a/uppdev/RichEditTest/main.cpp b/uppdev/RichEditTest/main.cpp index f998fdeb9..54e1b8093 100644 --- a/uppdev/RichEditTest/main.cpp +++ b/uppdev/RichEditTest/main.cpp @@ -1,5 +1,22 @@ #include +<<<<<<< .mine +#define Time XTime +#define Font XFont +#define Display XDisplay +#define Picture XPicture + +#include +//#include +//#include + +#undef Picture +#undef Time +#undef Font +#undef Display + +======= +>>>>>>> .r8093 using namespace Upp; String FileName() diff --git a/uppdev/cpp/cpp.cpp b/uppdev/cpp/cpp.cpp index 63e7781e7..58b67b9d2 100644 --- a/uppdev/cpp/cpp.cpp +++ b/uppdev/cpp/cpp.cpp @@ -1,5 +1,7 @@ #include "cpp.h" +#include + #define LLOG(x) bool IsSpc(byte c) @@ -7,6 +9,11 @@ bool IsSpc(byte c) return c > 0 && c <= 32; } +String CppMacro::ToString() const +{ + return String().Cat() << "(" << AsString(param) << ") " << body; +} + String CppMacro::Expand(const Vector& p) { String r; @@ -18,13 +25,25 @@ String CppMacro::Expand(const Vector& p) while(IsAlNum(*s) || *s == '_') s++; String id(b, s); - int q = param.Find(id); - if(q >= 0) { - if(q < p.GetCount()) - r.Cat(p[q]); + static String VA_ARGS("__VA_ARGS__"); // Speed optimization + if(id == VA_ARGS) { + bool next = false; + for(int i = param.GetCount(); i < p.GetCount(); i++) { + if(next) + r.Cat(", "); + r.Cat(p[i]); + next = true; + } + } + else { + int q = param.Find(id); + if(q >= 0) { + if(q < p.GetCount()) + r.Cat(p[q]); + } + else + r.Cat(id); } - else - r.Cat(id); continue; } if(s[0] == '#' && s[1] == '#') { @@ -50,7 +69,8 @@ String CppMacro::Expand(const Vector& p) int q = param.Find(id); if(q >= 0) { if(q <= p.GetCount()) { - r.Cat(AsCString(p[q])); + if(q < p.GetCount()) + r.Cat(AsCString(p[q])); s = ss; continue; } @@ -80,6 +100,8 @@ void Cpp::Define(const char *s) m.param.Add(p.ReadId()); p.Char(','); } + if(p.Char3('.', '.', '.')) + m.variadic = true; p.Char(')'); } m.body = p.GetPtr(); @@ -124,8 +146,18 @@ void Cpp::ParamAdd(Vector& param, const char *s, const char *e) String Cpp::Expand(const char *s) { - String r; + StringBuffer r; while(*s) { + if(incomment) { + if(s[0] == '*' && s[1] == '/') { + incomment = false; + s += 2; + r.Cat("*/"); + } + else + r.Cat(*s++); + } + else if(IsAlpha(*s) || *s == '_') { const char *b = s; s++; @@ -136,6 +168,7 @@ String Cpp::Expand(const char *s) if(q >= 0 && !macro[q].flag) { LLOG("Expanding " << id); Vector param; + const char *s0 = s; while(*s && (byte)*s <= ' ') s++; if(*s == '(') { s++; @@ -170,6 +203,8 @@ String Cpp::Expand(const char *s) else s++; } + else + s = s0; // otherwise we eat spaces after parameterless macro macro[q].flag = true; r.Cat(Expand(macro[q].Expand(param))); macro[q].flag = false; @@ -177,8 +212,66 @@ String Cpp::Expand(const char *s) else r.Cat(id); } + else + if(s[0] == '/' && s[1] == '*') { + incomment = true; + s += 2; + r.Cat("/*"); + } + else + if(s[0] == '/' && s[1] == '/') { + r.Cat(s); + break; + } else r.Cat(*s++); } return r; } + +String Cpp::Preprocess(Stream& in, bool needresult) +{ + incomment = false; + StringBuffer result; + result.Clear(); + result.Reserve(16384); + while(!in.IsEof()) { + String l = in.GetLine(); + int el = 0; + while(*l.Last() == '\\' && !in.IsEof()) { + el++; + l.Trim(l.GetLength() - 1); + l.Cat(in.GetLine()); + } + const char *s = l; + while(*s == ' ') + s++; + if(*s == '#') { + result.Cat("\n"); + if(strncmp(s + 1, "define", 6) == 0) + Define(s + 7); + } + else + if(needresult) + result.Cat(Expand(l) + "\n"); + else { + const char *s = l; + while(*s) { + if(s[0] == '/' && s[1] == '*') { + incomment = true; + s += 2; + } + else + if(s[0] == '*' && s[1] == '/') { + incomment = false; + s += 2; + } + s++; + } + } + if(needresult) + while(el--) + result.Cat("\n"); + } + return result; +} diff --git a/uppdev/cpp/cpp.h b/uppdev/cpp/cpp.h index 3b064cc36..ca9400b66 100644 --- a/uppdev/cpp/cpp.h +++ b/uppdev/cpp/cpp.h @@ -15,14 +15,18 @@ public: struct CppMacro : Moveable { String body; Index param; - bool flag; + bool variadic; + bool flag; // used when expanding macros to mark those use; MT incompatible (!) String Expand(const Vector& p); - CppMacro() { flag = false; } + String ToString() const; + + CppMacro() { flag = variadic = false; } }; struct Cpp { + bool incomment; VectorMap macro; void Define(const char *s); @@ -31,6 +35,8 @@ struct Cpp { void ParamAdd(Vector& param, const char *b, const char *e); String Expand(const char *s); + + String Preprocess(Stream& in, bool needresult = true); }; diff --git a/uppdev/cpp/main.cpp b/uppdev/cpp/main.cpp index c20946f68..7c6d4fa11 100644 --- a/uppdev/cpp/main.cpp +++ b/uppdev/cpp/main.cpp @@ -34,6 +34,7 @@ TEST4 CONSOLE_APP_MAIN { +/* { CppMacro m; m.body = "a + b * 123 - alfa"; @@ -44,7 +45,7 @@ CONSOLE_APP_MAIN x.Add("two"); DUMP(m.Expand(x)); } -/* + Cpp x; x.Define("TEST(a, b) |a|b|"); DUMP(x.Expand("This is: TEST(('\\1' , \"2\" \"4\" '4' ',' \",\"), 3)!")); @@ -54,14 +55,13 @@ CONSOLE_APP_MAIN DUMP(x.Expand("This is: TEST( \"1\" \"2\" \",\", ',')!")); */ Cpp x; + FileIn in0("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\crtdefs.h"); + x.Preprocess(in0); +// FileIn in("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\string.h"); FileIn in(GetDataFile("test.h")); - while(!in.IsEof()) { - String l = in.GetLine(); - if(l.StartsWith("#define")) - x.Define(~l + strlen("#define")); - else - LOG(/*l << " -> " << */x.Expand(l)); - } + LOG(x.Preprocess(in)); + LOG("---------------------------"); + DUMPM(x.macro); } // TEST:a,b:|a|b|\n diff --git a/uppdev/cpp/test.h b/uppdev/cpp/test.h index b041ea884..d0432a1bd 100644 --- a/uppdev/cpp/test.h +++ b/uppdev/cpp/test.h @@ -1,3 +1,18 @@ +#include + +#define eprintf(x, ...) if(x) printf(__VA_ARGS__) + +eprintf(TEST, "%d is %d", a, b, c) + +#define TEST test_expanded + +TEST /* TEST in comment */ TEST +/* TEST in comment 2 +TEST second line +*/ TEST + +TEST // TEST + #define __Expand1(x) x(1) #define __Expand2(x) __Expand1(x) x(2) #define __Expand3(x) __Expand2(x) x(3) @@ -102,7 +117,7 @@ #define E__NFValue(I) const Value& COMBINE(p, I) #define E__NFBody(I) String Format(const char *fmt, __List##I(E__NFValue)); -EXPAND: __Expand2(E__NFBody) +EXPAND: __Expand20(E__NFBody) ASSTRING(Just a test)